package com.igeek.service;

import com.igeek.dao.CustomerDao;
import com.igeek.domain.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jerry
 * @Company 极客营
 */
@Service
@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,timeout = -1,readOnly = false)
public class CustomerService {
    public CustomerService() {
        System.out.println("CustomerService create");
    }
    @Autowired
    private CustomerDao customerDao;
    //运行时异常，不会回滚
    @Transactional(noRollbackFor = RuntimeException.class)
    public void save(Customer c) {
        customerDao.save(c);
    }
    @Transactional(readOnly = true)
    public List<Customer> findAll() {
        return customerDao.findAll();
    }

    public void deleteById(String cust_id) {
        customerDao.deleteById(cust_id);
    }
    @Transactional(readOnly = true)
    public Customer findById(String cust_id) {
       return  customerDao.findById(cust_id);
    }

    public void update(Customer c) {
        customerDao.update(c);
    }
    @Transactional(readOnly = true)
    public List<Customer> queryByCondition(String cust_name) {
        return customerDao.queryByCondition(cust_name);
    }
}
